<template>
    <div class="block">
        <el-row>
            <el-col :span="24" class="qryform">
                <exSelect v-model="event_type" dictCode="eventType" multiple placeholder="请选择类型" clearable></exSelect>
                <el-button type="primary" class="ml20" @click="reQuery">查询</el-button>

            </el-col>
        </el-row>
        <stockTable ref="stockTable" style="width: 100%"></stockTable>
    </div>
</template>


<script>
import config from '~/config'
import dayjs from '~/plugins/day';

import datadict from '~/plugins/dict';
import stockTable from '~/components/stock/stockTable.vue';

export default {
    components:{
        stockTable
    },
    data() {
        return {
            event_type: "",
            startDate : "",
            endDate : "",
            dateRange : [],
            loading: false,
            eventlist: datadict.eventTypeList,
            eventMap : datadict.getEventTypeMap(),
        }
    },
     

    mounted() {
        this.setTableHeight();
        this.initDate();
    },

    methods: {
        setTableHeight(){
            var $this = this;
            setTimeout(function(){
                $this.$refs.stockTable.setTableHeight();
                $this.getDataList();
            },200)
        },
        initDate(s,e) {
            var start = new Date();
            var end = new Date();
            if(s){
                start = s;
            }else {
                start.setTime(start.getTime() - 3600 * 1000 * 24*1000);
            }
            if(e){
                end = e;
            }else {
                //  end.setTime(end.getTime() - 3600 * 1000 * 24 );
            }
            this.dateRange=[start,end];
            this.datechange();
        },
        datechange(){
            var daterange = this.dateRange;
            if(!daterange || daterange.length==0){
                this.startDate = "";
                this.endDate = "";
            }else {
                this.startDate = this.dateRange[0].getTime();
                this.endDate = this.dateRange[1].getTime();
            }
        },
        reQuery(){
            this.getDataList();
        },
        // 获取数据
        getDataList() {
            this.$refs.stockTable.clear();
            var args = "";
            var start ="";
            var end = "";
            if(!this.startDate){
                this.$message.error("请选择日期");
                return;
            }
            if(this.startDate && this.endDate){
                start = dayjs(this.startDate).format();
                end = dayjs(this.endDate).format();
                start = start.substring(0,10)
                end = end.substring(0,10)
            }
            args = `event_type=${this.event_type}&s=${start}&e=${end}&star=true`;
            this.loading = true;
            this.$axios.get(`${config.sapi}/api/stock/gtList?${args}`)
            .then((res) => {
                this.loading = false;
                if (res.data.code == 200) {
                    this.$refs.stockTable.setDataList(res.data.data);
                } else {
                    this.$message.error(res.data.message);
                }
            })
        },
    }
}
</script>

<style lang="less" scoped>
.flexdiv {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 10px;
    button{
        margin-left: 10px;
    }
}

.qryform{
    margin-bottom:10px;
    button{
        margin-top:0px;
        vertical-align: middle;
    }
}
.order-class{
    display: inline-block;
    margin-right: 10px;
    min-width: 50px;
}

.red{
    color: red;
}
.green{
    color: green;
}
.yellow{
    color: rgb(96, 22, 233)
}
.link-item{
    font-size: 12px;
}

</style>
